<template>
	<view class="app-product-list">
		<view class="app-item dir-left-nowrap" v-for="(item, index) in goods_list" :key="index" @click="route_go(item)">
			<image class="app-image" :src="item.goods.cover_pic"></image>
			<view class="out-dialog" v-if="item.miaosha_num == 0 && appSetting.is_show_stock == '1'">
				<image :src="appSetting.is_use_stock == '1' ? appImg.plugins_out : appSetting.sell_out_pic"></image>
			</view>
			<view class="app-content box-grow-1">
				<text class="app-name">{{item.goods.name}}</text>
				<view class="app-progress main-between cross-center">
					<view class="app-percentage" :style="{'border-color': theme.border}">
						<view class="percentage" :style="{width: `${item.goods.miaosha_percentage}`,'background': theme.background}"></view>
						<view class="app-already" :style="{'color': theme.color}">已抢购{{item.goods.miaosha_count}}{{item.goods.unit}}</view>
					</view>
					<view class="app-past" :style="{'color': theme.color}">仅剩{{item.goods.miaosha_num}}{{item.goods.unit}}</view>
				</view>
				<view class="price-button dir-left-nowrap main-between cross-bottom">
					<view class="price app-price dir-top-nowrap main-right cross-top">
                        <app-sup-vip :is_vip_card_user="item.vip_card_appoint.is_vip_card_user" margin="4rpx 0 0" v-if="item.vip_card_appoint.discount" :discount="item.vip_card_appoint.discount"></app-sup-vip>
                        <view :class="item.is_level && (item.level_price > 0 || item.level_price == 0) ? 'dir-top-nowrap' : 'dir-left-nowrap cross-bottom'" style="width: 100%;">
							<view class="app-min-price" :style="{'color': theme.color}">
	                            <text class="price-float" v-if="item.priceList.priceInt > 0 || item.priceList.priceInt == 0">￥</text>
	                            <text class="price-int" :class="item.priceList.priceInt > 0 || item.priceList.priceInt == 0 ? '' :'text'">{{item.priceList.priceInt}}</text>
	                            <text class="price-float">{{item.priceList.priceFloat}}</text>
							</view>
							<view v-if="item.is_level && (item.level_price > 0 || item.level_price == 0)" class="app-member-price" :style="{'background':theme.background_p,'color':theme.color}">
								<view class="t-omit">会员价
		                            <text class="price-float">￥</text>
		                            <text class="price-int">{{item.memberList.priceInt}}</text>
		                            <text v-if="item.memberList.priceFloat != '.00'" class="price-float">{{item.memberList.priceFloat}}</text>
								</view>
							</view>
							<view v-else class="app-original-price">￥{{item.goods.original_price}}</view>
						</view>
					</view>
					<view class="app-button" style="background-color: #CDCDCD;color: #fff;" v-if="item.miaosha_num == 0">下次再来</view>
					<view class="app-button" style="color: #ffffff;" :style="{'background-color': item.buy_goods_auth ? theme.background : '#999999'}" v-if="item.miaosha_num > 0">{{status === 1 ? '马上抢购' : '查看商品'}}</view>
				</view>
			</view>
		</view>
		<view :style="{width: `100%`, height: `${botHeight}rpx`}" v-if="empty"></view>
	</view>
</template>

<script>
    import {mapState, mapGetters} from 'vuex';

    export default {
		name: 'app-product-list',
	    data() {
            return {
                is_vip: true,
				disable: 'disable'
            }
	    },
        computed: {
            ...mapState({
                appImg: state => state.mallConfig.__wxapp_img.mall,
				appSetting: state => state.mallConfig.mall.setting,
                platform: function(state) {
                    return state.gConfig.systemInfo.platform;
                }
            }),
			...mapGetters('mallConfig', {
				getVideo: 'getVideo'
			}),
			goods_list() {
				let list = JSON.parse(JSON.stringify(this.list));
				for(let item of list) {
					item.priceList = this.handlePrice(item.goods.min_price);
					if(item.is_level && (item.level_price > 0 || item.level_price == 0)) {
						item.memberList = this.handlePrice(item.level_price);
					}
				}
				return list
			}
        },
	    props: {
            list: {
                type: Array,
	            default() {
                    return [];
	            }
            },
            status: {
                type: Number
            },
            empty: Boolean,
            botHeight: Number,
			theme: {
            	type: Object,
			},
	    },
	    methods: {
            route_go(data) {
				// #ifndef MP-BAIDU
				if (data.goods.video_url && this.getVideo == 1) {
				    // #ifdef MP
					uni.navigateTo({
						url: `/pages/goods/video?goods_id=${data.goods_id}&sign=miaosha`
					});
					// #endif
                    // #ifdef H5
                    uni.navigateTo({
                        url: `/plugins/miaosha/goods/goods?id=${data.goods_id}`,
                    });
                    // #endif
				} else {
					uni.navigateTo({
						url: `/plugins/miaosha/goods/goods?id=${data.goods_id}`,
					});
				}
				// #endif

				// #ifdef MP-BAIDU
				uni.navigateTo({
					url: `/plugins/miaosha/goods/goods?id=${data.goods_id}`,
				});
				// #endif
            }
	    }
    }
</script>

<style scoped lang="scss">
	.app-product-list {
		width: 100%;
		padding: 0 24rpx;
		overflow: hidden;
		.app-item {
			margin-top: 20rpx;
			width: #{702rpx};
			border-radius: 8rpx;
			background-color: white;
			position: relative;
			.app-image {
				width: #{256rpx};
				height: #{256rpx};
				border-top-left-radius: 8rpx;
				border-bottom-left-radius: 8rpx;
			}
			.out-dialog {
				width: #{256rpx};
				height: #{256rpx};
				position: absolute;
				top: 0;
				left: 0;
				background-color: rgba(0,0,0,.5);
				border-top-left-radius: 8rpx;
				border-bottom-left-radius: 8rpx;
				image {
					width: #{256rpx};
					height: #{256rpx};
					border-top-left-radius: 8rpx;
					border-bottom-left-radius: 8rpx;
				}
			}
			.app-content {
				width: 0;
				padding: 20rpx;
				.app-name {
					font-size: #{28rpx};
					color: #353535;
					word-break: break-all;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
				}
				.app-progress {
					margin-top: #{10rpx};
					font-size: 20rpx;
					height: 28rpx;
					line-height: 28rpx;
				}
				.app-percentage {
					width: #{284rpx};
					height: #{28rpx};
					border-radius: #{14rpx};
					border: 2rpx solid #ff4544;
					background-color: #ffffff;
					overflow: hidden;
					position: relative;
					.percentage {
						height: #{24rpx};
						min-width: #{24rpx};
						border-radius: #{12rpx};
						background-color: #ff4544;
						opacity: 0.25;
					}
					.app-already {
						position: absolute;
						height: 28rpx;
						line-height: 26rpx;
						width: 284rpx;
						text-align: center;
						font-size: 20rpx;
						color: #ff4544;
						top: 0;
						left: 0;
					}
				}
				.app-text {
					font-size: #{24rpx};
					margin-top: #{4rpx};
				}
				.app-already {
					color: #666666;
				}
				.app-past {
					color: #ff4544;
				}
				.price-button {
					min-height: #{132rpx};
					.app-price {
						max-width: 70%;
						.app-min-price {
	    					font-family: Alibaba;
							font-size: #{40rpx};
							margin-top: 10rpx;
							line-height: 1;
							margin-right: 14rpx;
							.text {
								font-size: 34rpx;
							}
							.price-float {
								font-size: 28rpx;
							}
						}
						.app-member-price {
							font-size: 24rpx;
							padding: 0 6rpx;
							overflow: hidden;
							white-space: nowrap;
						}
						.app-original-price {
							font-size: #{24rpx};
							color: #999999;
							text-decoration: line-through;
							line-height: 1;
						}
					}
					.app-button {
						width: #{120rpx};
						height: #{48rpx};
						font-size: #{24rpx};
						text-align: center;
						line-height: #{48rpx};
						border-radius: #{4rpx};
						margin-bottom: #{5rpx};
						flex-shrink: 0;
					}
					.no-button {
						background-color: white;
						border: #{1rpx} solid;
					}
				}
			}
		}
	}
</style>